package de.fhwf.mixedreality.agent;

import de.fhwf.mixedreality.client.AgentView;
import de.fhwf.mixedreality.client.IClient;
import de.fhwf.mixedreality.client.IClient.Team;
import de.fhwf.mixedreality.client.Vector;

public class GoalKickingBot extends AbstractBot {

	public GoalKickingBot(String server, ServerType type, Team team, int vtID,
			int rcID, String botName, String teamName, boolean simulationMode) {
		super(server, type, team, vtID, rcID, botName, teamName, simulationMode);
	}

	public void startup(IClient client) {
	}

	public boolean process(IClient client, AgentView view) {
		
		
		
		Vector v = client.getPositions().ball();
		if (v != null) {
			if (client.getMovements().canKick()) {
				Vector opGoalPole1 = client.getPositions().opGoalPole1();
				Vector opGoalPole2 = client.getPositions().opGoalPole2();
				Vector median = opGoalPole1.sum(opGoalPole2);
				Vector midOfOpGoal = new Vector(median.getAngle(),
						median.getLength() / 2);

				if (opGoalPole1.getLength() < opGoalPole2.getLength()) {

					median = midOfOpGoal.sum(opGoalPole1);
				} else {

					median = midOfOpGoal.sum(opGoalPole2);

				}

				Vector target = new Vector(median.getAngle(),
						median.getLength() / 2);
				int teamMateId = client.getPositions().closestTeammateToBall();
				Vector teamMate = client.getPositions().teammate(teamMateId);

				if (target.getLength() > 150.0) {

					client.getMovements().kick(target.getAngle(), 0.1);

				} else {

					Vector op = client.getPositions().opponent(
							client.getPositions().closestOpponentTo(target));
					median = median.sum(op);
					target = new Vector(median.getAngle(),
							median.getLength() / 2);
					client.getMovements().kick(target.getAngle(), 1.0);

				}

			} else {
				client.getMovements().goTo(v);
			}
		}

		return true;
	}

	public void terminate(IClient client) {
	}
	
	public Vector getMidOfOpGoal(IClient client){		
		return null;
	}
}
